package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.entity.Category;
import com.leyou.item.mapper.CategoryMapper;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {


    @Override
    public List<Category> queryCategoryByPid(Long pid) {
        List<Category> categories = query().eq("parent_id", pid).list();
        return categories;
    }

    @Override
    public CategoryDTO queryCategoryById(Long id) {
        return new CategoryDTO(this.getById(id));
    }

    @Override
    public List<CategoryDTO> queryCategoryByIds(List<Long> ids) {
        return CategoryDTO.convertEntityList(listByIds(ids));
    }

    @Override
    public List<CategoryDTO> queryCategoryByBrandId(Long bid) {
        List<CategoryDTO> categoryDTOS = baseMapper.queryCategoryByBrandId(bid);
//        List<CategoryDTO> categories = this.baseMapper.queryCategoryByBrandId(bid);
        return baseMapper.queryCategoryByBrandId(bid);
    }
}
